package com.minisoft.customer;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.List;
import java.util.Map;

public class UpdateUserInfo {

    private static final String URL = "http://user-service-pro.paas4.huafagroup.com/accountMainInfo/register";
    private static final String SOURCE_CODE = "SQXCX";
    private static final String APP_ID = "wx58d9554906d9a42c7"; // 假设这个值是固定的

    public static void main(String[] args) {
        // 读取Excel文件
        ExcelReader reader = ExcelUtil.getReader("D:\\中台建设\\客户中心/社群用户电话同步.xlsx");
        List<Map<String, Object>> readAll = reader.readAll();

        for (Map<String, Object> row : readAll) {
            // 构造请求体
            JSONObject body = JSONUtil.createObj()
                    .put("sourceCode", SOURCE_CODE)
                    .put("unionId", row.get("union_id"))
                    .put("openId", row.get("open_id"))
                    .put("telephone", row.get("mobile"))
                    .put("appId", APP_ID)
                    .put("name", null) // 如果你有name字段可以替换null为row.get("user_name")
                    .put("nickName", row.get("nick_name"))
                    .put("gender", 2) // 或者从Excel中获取性别值
                    .put("pictureLink", null);

            // 发送POST请求
            HttpResponse response = HttpRequest.post(URL)
                    .body(body.toString())
                    .execute();

            // 检查响应状态码
            if (response.isOk()) {
                System.out.println("成功更新用户信息：" + row.get("id"));
            } else {
                System.err.println("更新失败：" + response.body());
            }
        }
    }
}